package timing.ukulele.form.mapper;

import timing.ukulele.form.persistent.FormTemplateHistory;
import timing.ukulele.persistent.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface FromTemplateHistoryMapper extends BaseMapper<FormTemplateHistory> {

    @Select("SELECT MAX(version) FROM c_form_template_history WHERE id_ = #{id} OR use_id = #{id}")
    Integer getMaxVersion(@Param(value = "id") Long id);

    @Update("UPDATE c_form_template_history SET use_id = #{newId} WHERE id_ = #{oldId} OR use_id = #{oldId}")
    Integer updateUseId(@Param(value = "oldId") Long oldId, @Param(value = "newId") Long newId);
}
